on Command
Invoked when a command is received by a component this listener is registered with.
Implementers should typically use a switch statement or if-else-if chain on the name
parameter to identify the command and then process it accordingly, using the arg
parameter if provided.
The specific set of command names and the expected format or meaning of their arguments are defined by the system or component issuing the commands. Refer to the relevant documentation for available commands and their usage.
Example command handling:
public void onCommand(String name, String arg) {
if ("RESTART_PLAYER".equalsIgnoreCase(name)) {
// Code to restart the player
} else if ("SET_VOLUME".equalsIgnoreCase(name)) {
try {
int volumeLevel = Integer.parseInt(arg);
// Code to set player volume
} catch (NumberFormatException e) {
// Log error: invalid volume argument
}
} else if ("NAVIGATE_TO".equalsIgnoreCase(name)) {
// Code to navigate to a screen or URL specified in 'arg'
} else {
// Log: unhandled command
}
}
Parameters
The non-null name of the command to be executed (e.g., "PLAY_VIDEO", "SHOW_MESSAGE", "REBOOT_DEVICE"). Command names are often case-insensitive, but specific implementations should clarify this.
The argument associated with the command. This can be null
or an empty string if the command does not require an argument. The format and meaning of the argument are command-specific (e.g., a JSON string, a URL, an ID, a numerical value).